#ifndef COMMON_APPLICATION_H
#define COMMON_APPLICATION_H

#include <glad\glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
#include "GuiLayer.h"
#include "SceneSelector.h"
struct WindowParam {
	WindowParam(std::string name = "RayTracer", int width = 1280, int height = 960, bool isFullScreen = true)
		: mWindowName(name), mWidth(width), mHeight(height), mIsFullScreen(isFullScreen)
	{}
	std::string mWindowName;
	int mWidth;
	int mHeight;
	bool mIsFullScreen;
};

static void glfw_error_callback(int error, const char* description) {
	fprintf(stderr, "Glfw Error %d: %s\n", error, description);
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
	if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
		glfwSetWindowShouldClose(window, GLFW_TRUE);
}

class Application {
public:
	~Application();
	void Run();

	static Application* msInstance;
	static Application* GetInstance();
	GLFWwindow* GetWinowHandle();
	GuiLayer* GetGuiHandle();
	void SetParam(WindowParam param);
	void InitApplication();

	GLuint GetTexHandle() const { return screenTextureID; }
	void SetTexHandle(GLuint texId) { screenTextureID = texId; }
private:
	Application();
	bool CreateWindow();
	void DestroyWindow();
private:
	GLFWwindow* mWindowHandle = nullptr;
	GuiLayer* mImGuiLayer = nullptr;
	WindowParam mWindowParam;
	bool mIsRunning = false;
	ImVec4 clear_color = ImVec4(0.144f, 0.668f, 0.931f, 1.000f);
	GLuint screenTextureID;
	SceneSelector* mSceneSeletor;
};


#endif // !COMMON_APPLICATION_H


